import java.util.Arrays;

public class Solution2055 {
    public int[] platesBetweenCandles(String s, int[][] queries) {
        int[] l=new int[s.length()];
        int[] r=new int[s.length()];
        int cur=-1;
        for (int i=0;i<s.length();i++){
            if (s.charAt(i)=='|'){
                cur=i;
            }
            l[i]=cur;
        }
        cur=s.length();
        for (int i=s.length()-1;i>=0;i--){
            if (s.charAt(i)=='|'){
                cur=i;
            }
            r[i]=cur;
        }
        int[] sum=new int[s.length()+1];
        for (int i=0;i<s.length();i++){
            sum[i+1]=sum[i];
            if (s.charAt(i)=='*'){
                sum[i+1]++;
            }
        }
        int[] ans=new int[queries.length];
        for (int i=0;i<queries.length;i++){
            int ll=r[queries[i][0]];
            int rr=l[queries[i][1]];
            if (ll<rr){
                ans[i]=sum[rr]-sum[ll];
            }
        }
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution2055().platesBetweenCandles("**|**|***|", new int[][]{{2, 5}, {5, 9}})));
    }
}
